package v2ch01.findDirectories;

import java.io.*;
import java.nio.file.*;
import java.nio.file.attribute.*;

/**
 * @version 1.1 2012-05-31
 * @author Cay Horstmann
 */
public class FindDirectories
{
   public static void main(final String[] args) throws IOException
   {
      //System.out.println(System.getProperties());
      Path dir = Paths.get(args.length == 0 ? System.getProperty("user.home") : args[0]);
      dir=Paths.get("/Develop_Environment");
      BasicFileAttributes basicFileAttributes=Files.readAttributes(dir,BasicFileAttributes.class);
      System.out.println(basicFileAttributes.isDirectory());
      /*Files.walkFileTree(dir, new SimpleFileVisitor<Path>()
         {
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException
            {
               System.out.println("in vistiFile");
               System.out.println(file);
               if (attrs.isDirectory()) 
                  System.out.println(file);
               return FileVisitResult.CONTINUE;
            }
            public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException
            {
               System.out.println("in failed");
               return FileVisitResult.CONTINUE;
            }
         });*/

      Files.walkFileTree(Paths.get("D:","Develop_Environment"), new FileVisitor(){

         @Override
         public FileVisitResult preVisitDirectory(Object dir, BasicFileAttributes attrs) throws IOException {
            //访问文件夹之前调用

            System.out.println(dir);
            //
            return FileVisitResult.CONTINUE;
         }

         @Override
         public FileVisitResult visitFile(Object file,
                                          BasicFileAttributes attrs) throws IOException {
            // 访问文件调用
            //System.out.println(file);
            return FileVisitResult.CONTINUE;
         }

         @Override
         public FileVisitResult visitFileFailed(Object file, IOException exc)
                 throws IOException {
            // 访问文件失败时调用
            return FileVisitResult.CONTINUE;
         }

         @Override
         public FileVisitResult postVisitDirectory(Object dir,
                                                   IOException exc) throws IOException {
            // 访问文件夹之后调用
            return FileVisitResult.CONTINUE;
         }

      });
   }
}

